﻿using System.IO;
using System.IO.Compression;
using ICSharpCode.SharpZipLib.GZip;

namespace chromium.Utils
{
    public class GzipUtil
    {
        public static byte[] Compress(MemoryStream msTobeCompressed)
        {
            MemoryStream outStream = new MemoryStream();

            using (Stream compressStream = new GZipOutputStream(outStream))
            {
                msTobeCompressed.CopyTo(compressStream);
            }
            return outStream.ToArray();
        }

        public static byte[] DeCompress(byte[] value, int start, int count)
        {
            MemoryStream ms = new MemoryStream(value, start, count);
            MemoryStream outStream = new MemoryStream();
            using (Stream compressStream = new GZipStream(ms, CompressionMode.Decompress))
            {
                compressStream.CopyTo(outStream);
            }
            return outStream.ToArray();
        }
    }
}
